home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / communic / comdem / portdlg.txt < prev    next >
Text File  |  1991-07-11  |  5KB  |  177 lines

  1. Dim WorkPortName As String
  2. Dim WorkDCB As CommStateDCB
  3.  
  4. Sub UpdateDialogSettings (Index As Integer)
  5.     
  6.     For i% = 0 To 5
  7.         If WorkDCB.BaudRate = Val(Baud_Rate_Opt(i%).caption) Then
  8.             Baud_Rate_Opt(i%).value = TRUE
  9.         End If
  10.     Next i%
  11.  
  12.     Parity_Opt(Asc(WorkDCB.Parity)).value = TRUE
  13.     Data_Bits_Opt(Asc(WorkDCB.ByteSize) - 4).value = TRUE
  14.     Stop_bits_Opt(Asc(WorkDCB.StopBits)).value = TRUE
  15.  
  16. End Sub
  17.  
  18. Sub Comm_Device_Opt_Click (Index As Integer)
  19.  
  20.     WorkDCB.Id = Chr$(Index)
  21.     
  22.     WorkPortName = Comm_Device_Opt(Index).caption + ":"
  23.  
  24.     UpdateDialogSettings (Index)
  25.     DisplayQBOpen WorkDCB, WorkPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  26.  
  27. End Sub
  28.  
  29. Sub Cancel_Cmmd_Click ()
  30.     Unload PortDlg
  31. End Sub
  32.  
  33. Sub Reset_Cmmd_Click ()
  34.     
  35.     WorkDCB = CommState
  36.     UpdatePortDlg
  37.  
  38. End Sub
  39.  
  40. Sub Ok_Cmmd_Click ()
  41.  
  42.     If CommDeviceNum > 0 And CommHandle > -1 Then
  43.  
  44.         NoChange = TRUE
  45.  
  46.         If CommState.BaudRate <> WorkDCB.BaudRate Then NoChange = FALSE
  47.         If CommState.Parity <> WorkDCB.Parity Then NoChange = FALSE
  48.         If CommState.StopBits <> WorkDCB.StopBits Then NoChange = FALSE
  49.         If CommState.ByteSize <> WorkDCB.ByteSize Then NoChange = FALSE
  50.  
  51.         If NoChange = TRUE Then
  52.             Unload PortDlg
  53.             Exit Sub
  54.         End If
  55.  
  56.         UpdateCaption " DIALOG: Change Active Settings (Yes), Post-Pone (No), Return to Dialog (Cancel)", 0
  57.         
  58.         Result% = MsgBox("Port Already Active!" + Chr$(13) + "Activate settings Now?", 3 + 16 + 256, "Terminal Sampler II - Port Active")
  59.     
  60.         Select Case Result%
  61.             Case 6
  62.                 UpdateCaption " Changing Port Settings LIVE!", 0
  63.                 
  64.                 CommState = WorkDCB
  65.                 PostState = WorkDCB
  66.  
  67.                 CommPortName = WorkPortName
  68.                 PostPortName = WorkPortName
  69.  
  70.                 ApiErr% = SetCommState(WorkDCB)
  71.                 Unload PortDlg
  72.             Case 7
  73.                 UpdateCaption " Settings Post-Poned until next CONNECT", 0
  74.                 PostState = WorkDCB
  75.                 PostPortName = WorkPortName
  76.                 Unload PortDlg
  77.             Case Else
  78.                 DisplayQBOpen WorkDCB, WorkPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  79.         End Select
  80.  
  81.     Else
  82.  
  83.         CommState = WorkDCB
  84.         PostState = WorkDCB
  85.  
  86.         CommPortName = WorkPortName
  87.         PostPortName = WorkPortName
  88.         Unload PortDlg
  89.  
  90.     End If
  91.  
  92. End Sub
  93.  
  94. Sub Parity_Opt_Click (Index As Integer)
  95.  
  96.     If WorkDCB.Parity <> Chr$(Index) Then
  97.         
  98.         WorkDCB.Parity = Chr$(Index)
  99.         DisplayQBOpen WorkDCB, WorkPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  100.  
  101.     End If
  102.  
  103. End Sub
  104.  
  105. Sub Data_Bits_Opt_Click (Index As Integer)
  106.  
  107.     If WorkDCB.ByteSize <> Chr$(Index + 4) Then
  108.  
  109.         WorkDCB.ByteSize = Chr$(Index + 4)
  110.         DisplayQBOpen WorkDCB, WorkPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  111.     
  112.     End If
  113.  
  114. End Sub
  115.  
  116. Sub Baud_Rate_Opt_Click (Index As Integer)
  117.     
  118.     If WorkDCB.BaudRate <> Val(Baud_Rate_Opt(Index).caption) Then
  119.         WorkDCB.BaudRate = Val(Baud_Rate_Opt(Index).caption)
  120.         DisplayQBOpen WorkDCB, WorkPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  121.     End If
  122.  
  123. End Sub
  124.  
  125. Sub Stop_Bits_Opt_Click (Index As Integer)
  126.  
  127.     If WorkDCB.StopBits <> Chr$(Index) Then
  128.         
  129.         WorkDCB.StopBits = Chr$(Index)
  130.         DisplayQBOpen WorkDCB, WorkPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  131.  
  132.     End If
  133.  
  134. End Sub
  135.  
  136.  
  137. Sub Form_Load ()
  138.  
  139.     Remove_Items_From_SysMenu PortDlg
  140.  
  141.     WorkDCB = CommState
  142.     WorkPortName = CommPortName
  143.  
  144.     UpdatePortDlg
  145.  
  146.     CenterDialog PortDlg
  147.  
  148. End Sub
  149.  
  150. Sub UpdatePortDlg ()
  151.     
  152.     For i% = 1 To 0 Step -1
  153.         ApiErr% = OpenComm(Comm_Device_Opt(i%).caption + ":", 2048, 2048)
  154.         Select Case ApiErr%
  155.             Case IE_HARDWARE, IE_OPEN
  156.                 Comm_Device_Opt(i%).enabled = FALSE
  157.             Case Else
  158.                 ApiErr% = CloseComm(ApiErr%)
  159.                 Comm_Device_Opt(i%).enabled = TRUE
  160.                 Last% = i%
  161.         End Select
  162.         Comm_Device_Opt(i%).value = FALSE
  163.     Next i%
  164.  
  165.     If CommDeviceNum > 0 And CommHandle > -1 Then
  166.         Last% = CommDeviceNum - 1
  167.         Comm_Device_Opt(Last%).value = TRUE
  168.     Else
  169.         Comm_Device_Opt(Last%).value = TRUE
  170.     End If
  171.     
  172.     WorkDCB.Id = Chr$(Last%)
  173.     WorkPortName = Comm_Device_Opt(Last%).caption + ":"
  174.  
  175. End Sub
  176.  
  177.